<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
%>
<jsp:include page="../../import.jsp" flush="true" />

<body>


<SCRIPT LANGUAGE="JavaScript">
<!--
$(function(){
	$("#editDiv").dialog({
		autoOpen: false,
		bgiframe: true,
		height: 300,
		width:600,
		modal: true,
		buttons: {
			"提交": function() { 
				//$(this).dialog("close"); 
				_submit();
			}, 
			"取消": function() { 
				$(this).dialog("close"); 
			} 
		}
	});

});
//-->
</SCRIPT>



<!-- <input type="button" id="add" value="增加新业务" onclick="addNewTask();"/> -->
<!-- <s:property value="#session.QDEVELOP_LOGIN_SESSION_KEY.rid"/> -->
<jsp:include page="roleCache.jsp" flush="true" />
<table class="QueryTable">
<thead>
	<th><A HREF="javascript:goOrder('u.name')">用户名</A></th>
	<th>代理角色</th>
	<th>操作[<A HREF="javascript:addNewUserAgent();">新增用户代理</A>]</th>
</thead>
<!-- even odd -->
 <s:iterator value="rb.resultList" id="m" status="cust_stat">  
 <TR class='<s:if test="#cust_stat.even">anthor_tr</s:if>'>  
		<TD><s:property value="NAME"/></TD>
		<TD><SCRIPT LANGUAGE="JavaScript">document.write(toTranslate('<s:property value="RID"/>'));	</SCRIPT></TD>
		<TD>[<A HREF='javascript:editUserAgent(<s:property value="ID"/>,"<s:property value="RID"/>")'>修改</A>]
		<!-- <s:if test="#m.SENDNUM==null&&#m.WAITNUM==null&&#m.FINISHNUM==null"> -->
			/ [<A HREF='javascript:delUserAgent(<s:property value="ID"/>,"<s:property value="NAME"/>")'>删除</A>]
		<!-- </s:if> -->
		</TD>
</TR>
 </s:iterator> 
</table>
<jsp:include page="../../pageination.jsp" flush="true" />


<div id="editDiv" title="用户代理角色编辑" style="display:none">
	<span align='center' >
		<TABLE>
		<TR>
			<TD valign='top' >
			<div id="userSelect" style="display:none">
				请选择用户:<br>
				<select id="userSelectSpan" onchange="$('#id').val(this.options[this.selectedIndex].value);">
					<option value="">请选择用户</option>
				</select>
			</div>
			<FORM METHOD='POST' ACTION='<%=path%>/security/userAgent!update.action' onSubmit="return checkData();">
				<INPUT TYPE="hidden" NAME="id"   id="id" value=''>
				<INPUT TYPE="hidden" NAME="index"   id="index" value=''>
				<INPUT TYPE="hidden" NAME="rid"   id="rid" value=''>
			</FORM>
			</TD>
			<TD valign='top'>
			<iframe src='<%=path%>/security/roleInclude.action?forward=list&index=quaryRoles' frameborder=0  width="99%"  height="300px"  id="RolesFrame"></iframe>

			</TD>
		</TR>
		</TABLE>			
	
	</span>
</div>
<!-- <TEXTAREA id="debug" ROWS="50" COLS="100"></TEXTAREA> -->
</body>
<SCRIPT LANGUAGE="JavaScript">


var onclickNode  = function(id){
	alert(id);
}


var _submit = function(){
	
	if($('#id').val()==''){
	alert("必须选择用户！");
	}else{
		$('#userSelect').hide();
		$('#editDiv').dialog('close');
		wait.show();
		$('#rid').val(window.frames["RolesFrame"].getDtreeValues());
		$('form:first').submit();
	}
}

var editUserAgent = function(id,rid){	
	$('#editDiv').dialog('open');
	$('#id').val(id);
	window.frames["RolesFrame"].setDtreeValues(rid);
	$('#index').val('userAgentEdit');
	
}

var delUserAgent = function(id,name){
	if(confirm('确定删除任务【'+name+'】?')){
		$('#id').val(id);
		$('#index').val('userAgentDel');
		_submit();
	}
}
var addNewUserAgent = function(){
	$('#userSelect').show();
	window.frames["RolesFrame"].setDtreeValues(null);
	$('#editDiv').dialog('open');
	$('#index').val("userAgentInsert");
}

$.ajax({
		   type: "POST",
		   url: "<%=path%>/json/queryDB.action?index=quaryUsers&maxNum=100000000",
		   data:{},dataType:"json",
		   success: function(data){
				if(data!=null&&data.json.resultList!=null){
					var tmp;
					var oo = document.getElementById('userSelectSpan');
					for(var i=0;i<data.json.resultList.length;i++){
						tmp = data.json.resultList[i];
						 oo.options.add(new Option(tmp['NAME'],tmp['ID'])); 
					}
				}
		   }
});
</SCRIPT>
